<?php
	require_once("includes/db_connection.php");
	require_once("includes/functions.php");
	include("includes/main-header.php");
?>

<table id="structure">
	<tr>
		<td id="navigation">
			<h2>Menu:</h2>
			<ul>
				<li><a href="/">strona glowna</a></li>
			</ul>
		</td>
		<td id="page">
			
			<h2>Rejestracja</h2>
			
			<?
			function add_user_form() {
			global $PHP_SELF;
			?>
			
			<form method="post" action="<?php echo $PHP_SELF ?>">
			<input type="hidden" name="action" value="add_user">
				<p>Uzytkownik:</p>
				<p><input type="text" name="username" value="" size="15" maxlenght="15"></p>
				<p>Haslo:</p>
				<p><input type="password" name="password" value="" size="25" maxlenght="32"></p>
			<input type="submit" name="register" value="Rejestruj">
			</form>
			
			<?
			}
			
			function add_user() {
			
				global $PHP_SELF;
				global $username, $password;
				$password = md5($password);
			
				$query = "INSERT INTO users VALUES (NULL, '$username', '$password', 0)";
				$result = mysql_query($query);

				echo "<h3>Dodano uzytkownika $username </h3>";
				echo "Przejdz do <a href=\"login.php\">logowania</a>!";
			}

			switch($action) {
				case "add_user":
					add_user();
				break;
				default:
					add_user_form();
				break;
			}
			?>
			
		</td>
	</tr>
</table>
<?php require("includes/footer.php"); ?>